package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.CurriculumTable;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.CurriculumTableQueryObject;
import trlygjj.tanruiliyigenjinjin.service.ICurriculumTableService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("curriculumTable")
public class CurriculumTableController {

    @Autowired
    private ICurriculumTableService curriculumTableService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @RequiresPermissions("curriculumTable:index")
    @PermissionName("课程表页面")
    @RequestMapping("")
    public String index(){
        System.out.println("-----------------1-----------");
        return "curriculumTable/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @RequiresPermissions("curriculumTable:list")
    @PermissionName("课程表数据")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CurriculumTableQueryObject qo){
        PageResult result = curriculumTableService.query(qo);
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @RequiresPermissions("curriculumTable:listAll")
    @PermissionName("课程表所有数据")
    @RequestMapping("listAll")
    @ResponseBody
    public List<CurriculumTable> listAll(){
        return curriculumTableService.selectAll();
    }

    /**
     * 删除
     * @param curriculumTableId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumTable:delete")
    @PermissionName("课程表删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long curriculumTableId){
        JsonResult result = new JsonResult();
        try{
            curriculumTableService.deleteByPrimaryKey(curriculumTableId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param curriculumTable 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumTable:update")
    @PermissionName("课程表编辑")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(CurriculumTable curriculumTable){
        JsonResult result = new JsonResult();
        try{
            curriculumTableService.updateByPrimaryKey(curriculumTable);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param curriculumTable 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequiresPermissions("curriculumTable:save")
    @PermissionName("课程表保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(CurriculumTable curriculumTable){
        JsonResult result = new JsonResult();
        try{
            curriculumTableService.insert(curriculumTable);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 查询
     * @param date 根据时间
     * @return 返回CurriculumTable对象
     */
    @RequestMapping("selectCurriculumTableByDate")
    @ResponseBody
    //@DateTimeFormat(pattern = "yyyy-MM-dd")
    public List<CurriculumTable> selectCurriculumTableByDate(String date){
        System.out.println(date);
        return  curriculumTableService.selectCurriculumTableByDate(date);
    }




}
